/*
 * Middleware
 * Copyright (C) 2010/11
 * Riccardo Pulvirenti, Giuseppe Ravidà, Andrea Tino
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANDABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see http://www.gnu.org/licenses
 */

/*!
 * File: data_manager_proxy.hpp
 */

#ifndef _DATA_MANAGER_PROXY_HPP_
#define _DATA_MANAGER_PROXY_HPP_

#include <iostream>
#include <string>

#include "task_data.hpp"
#include "proxy_exception.hpp"

//-----------------------------------------------------------------------------
// Enum, struct, aliases
namespace middleware {
typedef struct {
	std::string ip_to_ui; /* IP used to send to ui data reqs */
	std::string port_to_ui; /* PORT used to send to ui data reqs */
	std::string ip_bind_ui; /* IP to bind to in order to listen for data reqs */
	std::string port_bind_ui; /* PORT to bind to in order to listen for data reqs */
} DataProxyConfig;
}
//-----------------------------------------------------------------------------
// Class definitions
namespace middleware {
/*!
 * Network interface for ui and worker to communicate in order to send and
 * receive data.
 */
class DataManagerProxy : public TaskData {
	/*!
	 * To let factory build properly this object, we provide access to every
	 * part of it.
	 */
	friend class DataProxyFactory;
public:
	/*!
	 * Destructor.
	 */
	~DataManagerProxy();
	/*!
	 * Accept a request and sends requested data.
	 */
	void accept_req_send_data(Data data) throw(ProxyException);
	/*!
	 * Sends request for data.
	 */
	Data req_data() throw(ProxyException);
private:
	/*!
	 * Privately constructs the object. Default configuration with local
	 * loopback addresses and invalid ports.
	 */
	DataManagerProxy();
	/*!
	 * Privately constructs the object. Assigning configuration.
	 */
	explicit DataManagerProxy(DataProxyConfig conf);
	/*!
	 * Parameters for proxy.
	 */
	DataProxyConfig _config;
}; /* DataManagerProxy */
} /* middleware */

#endif
